<template>
  <el-row>
   <el-form :model="form" label-width="80px" :rules="rules" ref="form">
     <el-col :span="24">
      <el-form-item label="授权码" prop="build_org">
       <el-input v-model="form.build_org" placeholder="请输入授权码"></el-input>
     </el-form-item>
     </el-col>     
     <el-col :span="24" class="box-style">
    <el-button size="medium" type="primary" @click="onSave('form')">保存</el-button>
    <el-button size="medium" @click="onBack" >取消</el-button>
     </el-col>
   </el-form>
  </el-row>
</template>
<script>
import { SendCodeApi } from '@/services/Public'
export default {
props:{
todos:Number,
catchSave:Function,
catchBack:Function
},
data(){
  return{
form:{
  build_org:''
},
rules:{
  build_org:[
    {required:true,message:'授权码不能为空',trigger:'change'}
  ]
}}
},
methods:{
//保存
onSave(data){
this.$refs[data].validate((valid)=>{
  if(valid){
     SendCodeApi.addJoinOrg({
       data:{
company_code:this.form.build_org,
user_id:window.localStorage.user_id
       }
     }).then((res)=>{
this.catchSave('加入组织');
     }).catch((error)=>{
       console.log(error)
     })
  }else{
    console.log('error')
  }
})
},
//取消
onBack(){
  this.catchBack('加入组织')
}
},
watch:{
  todos(n,o){
  console.log('watch-todos=',n)
  }
},
created(){
console.log('created-todos=',this.todos)
}
}
</script>

<style lang="scss" scoped>
.box-style{
  margin-top:20px;
  text-align:center;
}
</style>